<?php

namespace app\models\search;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\CtiCdrWav;

/**
 * CtiCdrWavSearch represents the model behind the search form of `app\models\CtiCdrWav`.
 */
class CtiCdrWavSearch extends CtiCdrWav
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['absPath', 'httpPath', 'uuid', 'from', 'to', 'zuoxi'], 'safe'],
            [['createTime', 'id'], 'integer'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = CtiCdrWav::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
        ]);

        if (count($params['CtiCdrWavSearch']['sjqj'])>1){
            $query->andFilterWhere(['between','createTime',$params['CtiCdrWavSearch']['sjqj'][0]/1000 ,$params['CtiCdrWavSearch']['sjqj'][1]/1000 ]);
        }

        $query->andFilterWhere(['like', 'absPath', $this->absPath])
            ->andFilterWhere(['like', 'httpPath', $this->httpPath])
            ->andFilterWhere(['like', 'uuid', $this->uuid])
            ->andFilterWhere(['like', 'from', $this->from])
            ->andFilterWhere(['like', 'to', $this->to])
            ->andFilterWhere(['like', 'zuoxi', $this->zuoxi]);

        return $dataProvider;
    }
}
